package com.kfm.springmybatis.Collection;

import com.kfm.springmybatis.model.Dept;
import com.kfm.springmybatis.model.Emp;
import com.kfm.springmybatis.service.DeptService;
import com.kfm.springmybatis.service.EmpService;
import com.kfm.springmybatis.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class EmpCollection {
    @Autowired
    EmpService empService;
    @Autowired
    DeptService deptService;
    @RequestMapping("/empList")
    public ModelAndView selectAll(){
        ModelAndView mv = new ModelAndView();
        List<Emp> emps = empService.selectAll();
        List<Dept> depts = deptService.selectAll();
        mv.addObject(Constants.EMP_LIST_MORE,emps);
        mv.addObject(Constants.DEPT_LIST_MORE,depts);
        mv.setViewName("emp");
        return mv;
    }
    @RequestMapping("/deptList")
    public ModelAndView selectAll2(){
        ModelAndView mv = new ModelAndView();
        List<Dept> depts = deptService.selectAll();
        mv.addObject(Constants.DEPT_LIST_MORE,depts);
        mv.setViewName("dept");
        return mv;
    }
}
